home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17669 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  46 lines

  1. Path: holly.ACNS.ColoState.EDU!not-for-mail
  2. From: corbyh@holly.ACNS.ColoState.EDU (Corby S. Hudnall)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Circular Usage (forward declaration?)
  5. Date: 16 Apr 1996 19:11:11 -0600
  6. Organization: Colorado State University, Fort Collins, CO  80523
  7. Distribution: world
  8. Message-ID: <4l1gff$142e@holly.ACNS.ColoState.EDU>
  9. References: <MRW.96Apr16184800@tobago.siemens.ch>
  10. NNTP-Posting-Host: holly.acns.colostate.edu
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Waeckerlin Marc wrote:
  14. : class A
  15. : {
  16. :     B x;
  17. : };
  18.  
  19. : class B
  20. : {
  21. :     A x;
  22. : };
  23. As your title implies, use a forward declaration of B like so:
  24.  
  25. class B;
  26.  
  27. class A { B* Bptr; };
  28.  
  29. class B { A* Aptr; };
  30.  
  31. You can of course expand this example to do whatever you need it to.  
  32. Good Luck.
  33.  
  34. // ------------ BEGIN SIGNATURE ---------------
  35. #include <iostream.h>
  36. void main(void)
  37. {
  38.   cout << "\aName:\tCorby S. Hudnall\n"
  39.        << "School:\tColorado State University\n"
  40.        << "\tDepartement of Computer Science\n"
  41.        << "EMail:\thudnall@CS.ColoState.EDU\n"
  42.        << "URL:\thttp://WWW.CS.ColoState.EDU/~hudnall\n";
  43. }
  44. // ------------ END SIGNATURE -----------------
  45.  
  46.